<template>
  <a-card  style="overflow-y: auto">
    <a-tabs defaultActiveKey="1">
      <a-tab-pane tab="流程选项" key="1" >
        <a-row v-if="(flag==='' || flag === item.description)" v-for="(item,index) in flowOptions" style="margin-top: 10px">
          <a-col :span="6" style="text-align: right">
            <span style="margin-right: 10px">{{item.text && item.text!==''?item.text+' :':'' }} </span>
          </a-col>
          <a-col :span="18">
            <a-radio-group v-if="getTypeSubString(item.value) === 'radio'" v-model="item.saveValue" @change="onChange($event,index)">
              <a-radio v-for="optin in getOptionSubString(item.value)" :value="optin.split('|')[1]">
                {{ optin.split('|')[0] }}
              </a-radio>
            </a-radio-group>
          </a-col>
        </a-row>


      </a-tab-pane>
    </a-tabs>
  </a-card>
</template>

<script>
  import { httpAction,getAction } from '@/api/manage'
  import { postAction } from '../../api/manage'
  export default {
    name: 'FlowOptionModal',
    props: {
      planId: String,
      disabled: Boolean
    },
    computed:{

    },
    data(){
      return{
        flag:'',
        flowOptions:[],
        model:{},
        url: {
          getFlowOptions:'/sys/dict/getDictItems/flowOptions',
          getVariablesByExecutionId:'handle/getVariables/',
        }
      }
    },
    created() {
      this.getFlowOptions()
    },
    methods: {
      onChange(e,index){
        this.flowOptions[index].saveValue = e.target.value
        this.$forceUpdate()
      },
      /** 查看流程中已保存的流程选项*/
      getVariablesByExecutionId(procInstId){
        const that = this
        getAction(that.url.getVariablesByExecutionId+procInstId,{}).then(res=>{
          if(res.success && res.result){
            for (let i = 0; i < that.flowOptions.length; i++) {
              if(that.flowOptions[i].value.indexOf('isYw')!==-1){
                that.flowOptions[i].saveValue = res.result.isYw
              }else if(that.flowOptions[i].value.indexOf('isCw')!==-1){
                that.flowOptions[i].saveValue = res.result.isCw
              }
            }
            that.$forceUpdate()
          }
        })
      },
      getOptionSubString(str){
        let optionStr = str.substring(str.indexOf('(')+1,str.indexOf(')'))
        // console.log(optionStr.split(','),'返回的数据格式')
        return optionStr.split(',')
      },
      getTypeSubString(str){
        return str.substring(str.indexOf('[')+1,str.indexOf(']'))
      },
      getObjSubString(str){
        return str.substring(str.indexOf('{')+1,str.indexOf('}'))
      },
      getFlowOptions(){
        getAction(this.url.getFlowOptions).then(res=>{
          if(res.success){
            for (let i = 0; i < res.result.length; i++) {
              res.result.saveValue = ''
            }
            this.flowOptions = res.result
          }
        })
      },
      initData(id,flag){
        //预留id 供以后扩展  肯定会扩展的 相信我
        console.log(flag,"flowflag")
        if(!flag || flag===''){
          this.flag = ''
        }else{
          this.flag = flag
        }

        for (let i = 0; i < this.flowOptions.length; i++) {
          if(this.flowOptions[i].saveValue){
            this.flowOptions[i].saveValue = undefined
          }
        }

      },
      getData(){
        let dataObj={}
        for (let i = 0; i < this.flowOptions.length; i++) {
          dataObj[this.getObjSubString(this.flowOptions[i].value)] = this.flowOptions[i].saveValue
        }
        return dataObj;
      },
      check(){
        for (let i = 0; i < this.flowOptions.length; i++) {
          if((this.flag==='' || this.flag === this.flowOptions[i].description) && (!this.flowOptions[i].saveValue || this.flowOptions[i].saveValue==='')){
            this.$message.warn("请选择 "+this.flowOptions[i].text)
            return false
          }
        }
        return true
      }
    }
  }
</script>

<style scoped>

</style>